package com.woniuxy.education.service.impl;

import com.woniuxy.education.entity.Ncee;
import com.woniuxy.education.entity.Question_ask;
import com.woniuxy.education.entity.Teacher;
import com.woniuxy.education.mapper.HomeworkAssignmentsMapper;
import com.woniuxy.education.mapper.QuestionAnswerMapper;
import com.woniuxy.education.service.QuestionAnswerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class QuestionAnswerServiceImpl implements QuestionAnswerService {

    @Autowired
    HomeworkAssignmentsMapper homeworkAssignmentsMapper;
    @Autowired
    QuestionAnswerMapper questionAnswerMapper;


    //查出提问
    @Override
    public List<Question_ask> getQuestionAsk(String userid) {

        Teacher teacher = homeworkAssignmentsMapper.selectteacher(userid);
        String tname=null;
        if(teacher!=null){
            //获取教师姓名
             tname=teacher.getName();

        }
        else {
            return null;

        }
       // System.out.println(tname);
     //获取提问,1表示未回复
        String state="1";

        List<Question_ask> questionAsks = questionAnswerMapper.findQuestionAsk(tname,state);

        return questionAsks;
    }

    //回复
    @Override
    public void insertQuestionAnswer(String id,String answer) {
        //查询提问，根据ID
        Question_ask question_ask = questionAnswerMapper.selectQuestionAsk(id);
       // System.out.println(question_ask);
        //回复
        //赋值，回复答案
        question_ask.setAnswer(answer);
        //回复教师
        question_ask.setRecovery_tea(question_ask.getTea_name());

       questionAnswerMapper.insertQuestionAnswer(question_ask);
    }


    //高考数据录入
    @Override
    public void insertNceeData(Ncee ncee) {
        //System.out.println(ncee);
        questionAnswerMapper.insertNceeData(ncee);
    }
}
